﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace KPIS.GERP.GIMS.APP.APP_UI.Form
{
    public partial class Sys_File_Form : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string dest_path = Request.QueryString["file"];
            string xx = HttpUtility.UrlEncode(Request.QueryString["file"], System.Text.Encoding.UTF8);
            string xy = HttpUtility.UrlDecode(xx, System.Text.Encoding.UTF8);
            string file_name = Path.GetFileName(dest_path);
            string extension = Path.GetExtension(dest_path);
            string type = "";
            if (extension != null)
            {
                switch (extension.ToLower())
                {
                    case ".htm":
                    case ".html":
                        type = "text/HTML";
                        break;

                    case ".doc":
                    case ".rtf":
                        type = "application/msword";
                        break;

                    case ".xls":
                        type = "application/vnd.ms-excel";
                        break;

                    case ".ppt":
                    case ".pps":
                        type = "application/vnd.ms-powerpoint";
                        break;

                    case ".docx":
                        type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                        break;

                    case ".xlsx":
                        type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                        break;

                    case ".pdf":
                        type = "application/pdf";
                        break;
                }
            }

            Response.ContentType = type;
            Response.WriteFile(dest_path);
            Response.End();
        }
    }
}
